import React, { useState, useEffect } from 'react';

function UseClock(){
	let [date,setDate] = useState(0);
	// const useclock = useRef();
	const arr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
	const data = new Date();
	useEffect(()=>{
		const timerID = setInterval(()=>setDate(date = new Date()), 1000);
		return () => clearInterval(timerID);
	},[]);
	// const showTime = function(){
	// 	const day = date.getDay(); 
	// 	return arr.filter((v,i)=>i === day) + this.date.toLocaleTimeString()
	// }
	// const day = this.date.getDay()
	return (
		<div>
		{arr.filter((v,i)=>i === data.getDay()) + data.toLocaleTimeString()}
		</div>
	)
}
export default UseClock;